package cn.itsource.pethome.controller;

import cn.itsource.pethome.domain.Employee;
import cn.itsource.pethome.query.EmployeeQuery;
import cn.itsource.pethome.result.JSONResult;
import cn.itsource.pethome.result.PageList;
import cn.itsource.pethome.service.EmployeeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @
 */
@RestController
@RequestMapping("/emp")
public class EmployeeController extends BaseController{

    @Autowired
    private EmployeeService employeeService;

    /**
     * 根据ID查询某个部门详情
     */
    @GetMapping("/one/{id}")
    @ApiOperation(value = "查询部门",notes = "根据ID查询某个部门详情")
    public Employee selectDeptById(@ApiParam(value = "需要查询的部门id",required = true)@PathVariable("id") Long id) {
        return employeeService.selectById(id);
    }

    /**
     * 查询所有部门信息（不分页）
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询所有部门",notes = "查询所有部门不分页")
    public JSONResult list() {
        List<Employee> list = employeeService.list();
        return JSONResult.success(list);
    }

    /**
     * 保存/修改部门信息
     */
    @ApiResponses({@ApiResponse(code = 200,message = "OK",response = JSONResult.class)})
    @ApiOperation(value = "新增或者修改部门信息",notes = "保存/修改部门信息到数据库")
    @PostMapping("/saveOrUpdate")
    public JSONResult saveOrUpdate(@ApiParam(value = "新增或修改的部门",required = true) @RequestBody Employee dept) {
        return employeeService.saveOrUpdate(dept);
    }

    /**
     * 查询所有部门信息（分页）
     */
    @PostMapping("/pagelist")
    @ApiOperation(value = "查询所有部门信息",notes = "查询所有部门信息（分页）")
    public JSONResult pagelist(@ApiParam(value = "分页的条件",required = true)@RequestBody EmployeeQuery query) {
        PageList<Employee> list = employeeService.pagelist(query);
        return JSONResult.success(list);
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "删除部门信息",notes = "根据id批量删除指定的部门")
    public JSONResult deleteBatch(@ApiParam(value = "需要删除的ID数组",required = true)@RequestBody EmployeeQuery query){
        employeeService.deleteBatch(query);
        return employeeService.deleteBatch(query);
    }
    @DeleteMapping ("delete/{id}")
    @ApiOperation(value = "删除部门信息",notes = "根据id批量指定的部门")
    public JSONResult delete(@ApiParam(value = "需要删除的ID数组",required = true)@PathVariable("id") Long id){
        return employeeService.delete(id);
    }
}